package com.cwnu.onlinemall.service;

import com.cwnu.onlinemall.mapper.MallCommodityMapper;
import com.cwnu.onlinemall.pojo.MallCommodity;
import com.cwnu.onlinemall.pojo.MallCommodityExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityServiceImpl implements CommodityService {
    @Autowired
    MallCommodityMapper mallCommodityMapper;
    @Override
    public List<MallCommodity> SelectAll() {
        List<MallCommodity> mallCommodityList=mallCommodityMapper.selectByExample(null);
        return mallCommodityList;
    }

    @Override
    public Integer insert(MallCommodity mallCommodity) {
        return mallCommodityMapper.insertSelective(mallCommodity);
    }

    @Override
    public MallCommodity selectById(Integer id) {
        return mallCommodityMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MallCommodity> selectByCategoryName(String category) {
        MallCommodityExample mallCommodityExample=new MallCommodityExample();
        MallCommodityExample.Criteria criteria=mallCommodityExample.or();
        criteria.andCommodityCategoryEqualTo(category);
        List<MallCommodity> mallCommodityList = mallCommodityMapper.selectByExample(mallCommodityExample);
        return mallCommodityList;

    }

    @Override
    public Integer updateById(MallCommodity mallCommodity) {
        return mallCommodityMapper.updateByPrimaryKeySelective(mallCommodity);
    }

    @Override
    public Integer deleteById(Integer id) {
        return mallCommodityMapper.deleteByPrimaryKey(id);
    }
}
